//
//  BookingHotelVC.swift
//  DLuxTravel
//
//  Created by 陆涛 on 2018/12/3.
//  Copyright © 2018 imguider. All rights reserved.
//

import UIKit

class BookingHotelVC: BaseVC {

    @IBOutlet weak var headView: UIView!
    
    @IBOutlet weak var checkInInfoBtn: UIButton!
    @IBOutlet weak var typeBtn: UIButton!
    @IBOutlet weak var bookingInfoBtn: UIButton!
    
    @IBOutlet weak var containerView: UIView!
    
    weak var checkinInfoVC: UIViewController?
    
    lazy var sb:UIStoryboard = {
        
        return UIStoryboard.init(name: "Booking", bundle: nil)
    }()
    
    lazy var typeVC: UIViewController = {
        
        return sb.instantiateViewController(withIdentifier: "HotelTypeVC")
    }()
    
    lazy var bookingInfoVC: UIViewController = {
        
        return sb.instantiateViewController(withIdentifier: "HotelBookingInfoVC")
    }()
    
    private var containerCount: Int {
        
        return checkinInfoVC?.navigationController?.viewControllers.count ?? 0
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()

        setupUI()
    }
    
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        
        super.prepare(for: segue, sender: sender)
        
        if let nav = segue.destination as? UINavigationController {
            
            checkinInfoVC = nav.viewControllers.first
            
        }
        
    }
    
    private func setupUI() {
        
        self.title = "预定"
        headView.addShadow(.hotelDetail)
        showView(0)
    }

    private func showView(_ tag:Int) {
        
        switch tag {
        case 0: //入住信息
            
            if containerCount == 1 {
                
                return
            }
            
            if containerCount > 1 {
                
                checkinInfoVC?.navigationController?.popToRootViewController(animated: true)
            }
            
            checkInInfoBtn.setTitleColor(kTitleColor, for: .normal)
            typeBtn.setTitleColor(kContentColor, for: .normal)
            bookingInfoBtn.setTitleColor(kContentColor, for: .normal)

        case 1: //选择房型
            
            if containerCount == 2 {
                
                return
            }
            
            if containerCount == 1 {
                
                checkinInfoVC?.navigationController?.pushViewController(typeVC, animated: true)
            } else if containerCount == 3 {
                
                checkinInfoVC?.navigationController?.popViewController(animated: true)
            }
            
            checkInInfoBtn.setTitleColor(kTitleColor, for: .normal)
            typeBtn.setTitleColor(kTitleColor, for: .normal)
            bookingInfoBtn.setTitleColor(kContentColor, for: .normal)

        case 2: //预定信息
            
            if containerCount == 1 || containerCount == 3 {
                
                return
            }
            
            if containerCount == 2 {
                
                checkinInfoVC?.navigationController?.pushViewController(bookingInfoVC, animated: true)
            }
            
            checkInInfoBtn.setTitleColor(kTitleColor, for: .normal)
            typeBtn.setTitleColor(kTitleColor, for: .normal)
            bookingInfoBtn.setTitleColor(kTitleColor, for: .normal)

        default:
            break
        }
    }
    
    @IBAction func selectPageAction(_ sender: UIButton) {
        
        let tag = sender.tag
        
        showView(tag)
    }
}
